home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
X User Tools
/
X User Tools (O'Reilly and Associates)(1994).ISO
/
sources
/
xbmbrows
/
xbmbro31.z
/
xbmbro31
/
xbmbrowser3.1
/
xbmbrowser.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-05
|
9KB
|
263 lines
char copyright[]="xbmbrowser Version 3.1 (c) Copyright Ashley Roll, 1992.";
/*
*****************************************************************************
** xbmbrowser version 3.1 (c) Copyright Ashley Roll, 1992.
** FILE: xbmbrowser.c
**
** xbmbrowser is Public Domain. However it, and all the code still belong to me.
** I do, however grant permission for you to freely copy and distribute it on
** the condition that this and all other copyright notices remain unchanged in
** all distributions.
**
** This software comes with NO warranty whatsoever. I therefore take no
** responsibility for any damages, losses or problems that the program may
** cause.
*****************************************************************************
*/
#define MAIN
#include "xbmbrowser.h"
#include "patchlevel.h"
#include "user-menu.h"
#include "icon.xbm"
/* -------------------------- */
static Atom wm_delete_window; /* insure that delete window works */
static XtActionsRec actions[] = { /* declare possible actions */
/* action_name, routine */
{ "quit", DoQuit },
{ "CD", change_dir },
{ "Set_Name", set_name },
{ "Set_Label", set_label },
{ "Ok", Ok },
{ "Pos_Dir", pos_dir },
};
/* translation table for label widgets for the bitmaps */
char Translations[] =
"<EnterWindow>: Set_Name() \n\
<LeaveWindow>: Set_Label() \n\
<BtnDown>: XawPositionSimpleMenu(bitmapMenu) MenuPopup(bitmapMenu) \n\
<BtnUp>: MenuPopdown(bitmapMenu)";
/* translation table for the dialogWidget (directory name) */
static char text_trans[] =
"<Key>Return: CD() \n\
Ctrl<Key>M: CD() \n\
<Btn3Down>: Pos_Dir() MenuPopup(DirPopup) ";
/* translation table for the list widget */
static char list_trans[] =
"<Enter>: Set() \n\
<Leave>: Unset() \n\
<BtnMotion>: Set() \n\
<BtnUp>: MenuPopdown(DirPopup) Notify() Unset()";
/* translation table for the transient shell containing the list */
/* this translation makes the list popdown if the button is released
outside the window */
static char tshell_trans[] =
"<BtnUp>: MenuPopdown(DirPopup)";
/* fallback resources */
static char *fall_back[] = {
".XbmBrowser.width: 450",
".XbmBrowser.height: 500",
".XbmBrowser.iconName: browser",
".XbmBrowser.?.TransientShell.width: 350",
".XbmBrowser.main.buttons.Command.width: 70",
NULL
};
/* -------------------------- */
main(argc, argv)
int argc;
char **argv;
{
XtAppContext appcon;
Widget button;
ac = argc;
av = argv;
dialogs_made = FALSE;
directory = dname;
bitmap_info = NULL;
/* Setup the toplevel window */
{
Pixmap icon;
char title[80];
sprintf(title,"XbmBrowser Version %s",PATCHLEVEL);
toplevel = XtVaAppInitialize(
&appcon, "XbmBrowser", /* app context, ClassName */
NULL, 0, /* app command line options */
&argc, argv, /* command line */
fall_back, /* Fall back resources */
XtNtitle,(XtArgVal)title,
NULL); /* End Va resource list */
icon = XCreateBitmapFromData(
XtDisplay(toplevel), RootWindowOfScreen(XtScreen(toplevel)),
(char *)icon_bits, icon_width, icon_height);
XtVaSetValues(toplevel,XtNiconPixmap, icon,NULL);
}
XtAppAddActions(appcon, actions, XtNumber(actions));
if( argc > 2 ) useage();
if(argc == 2) {
if(chdir(argv[1]) != 0) {
fprintf(stderr,"xbmbrowser: couldn't chdir to '%s'\n",argv[1]);
exit(0);
}
}
(void) getcwd(dname,253);
/* create the cursors */
normalCursor = XCreateFontCursor(XtDisplay(toplevel),XC_left_ptr);
waitCursor = XCreateFontCursor(XtDisplay(toplevel),XC_watch);
/* create a paned widget to put everything into */
mainpw = XtVaCreateManagedWidget("main",panedWidgetClass,toplevel,
XtNcursor,(XtArgVal)normalCursor,
NULL);
/* create the form widget to put the buttons in */
bfw = XtVaCreateManagedWidget("buttons",formWidgetClass,mainpw,
XtNshowGrip,(XtArgVal)False,
XtNskipAdjust,(XtArgVal)True,NULL);
/* create the Buttons */
button = XtVaCreateManagedWidget("quit",commandWidgetClass,bfw,
XtNlabel,(XtArgVal)"Quit",NULL);
XtAddCallback(button,"callback",DoQuit,NULL);
button = XtVaCreateManagedWidget("help",commandWidgetClass,bfw,
XtNfromHoriz,(XtArgVal)button,
XtNlabel,(XtArgVal)"Help",NULL);
XtAddCallback(button,"callback",Show_Help,NULL);
button = XtVaCreateManagedWidget("rescan",commandWidgetClass,bfw,
XtNfromHoriz,(XtArgVal)button,
XtNlabel,(XtArgVal)"Rescan",NULL);
XtAddCallback(button,"callback",rescan,NULL);
/* dialogWidget to hold and get the directory to read from */
atw = XtVaCreateManagedWidget("directory", dialogWidgetClass, mainpw,
XtNlabel,(XtArgVal)"Current Directory",
XtNvalue,(XtArgVal)dname,
XtNshowGrip,(XtArgVal)False,
XtNskipAdjust,(XtArgVal)True,
NULL);
XtOverrideTranslations(XtNameToWidget(atw,"value"),
XtParseTranslationTable(text_trans));
/* create the dirMenu list widget in a popup shell. */
dirPopup = XtVaCreatePopupShell("DirPopup",transientShellWidgetClass,atw,
XtNoverrideRedirect,(XtArgVal)True,
XtNallowShellResize,(XtArgVal)True,
NULL);
XtOverrideTranslations(dirPopup,XtParseTranslationTable(tshell_trans));
dirList = XtVaCreateManagedWidget("DirList",listWidgetClass,dirPopup,
NULL);
XtAddCallback(dirList,"callback",dir_menu,NULL);
XtOverrideTranslations(dirList,XtParseTranslationTable(list_trans));
/* label widget to hold the name of the current bitmap */
strcpy( label_info, "Loading Bitmaps" );
lw = XtVaCreateManagedWidget("label",labelWidgetClass,mainpw,
XtNlabel, (XtArgVal)label_info,
XtNshowGrip, (XtArgVal)False,
XtNskipAdjust, (XtArgVal)True,NULL);
/* create a viewport widget to stick the bitmaps in */
{ int width;
XtVaGetValues(toplevel,XtNwidth,&width,NULL);
phw = XtVaCreateManagedWidget("viewport",viewportWidgetClass,mainpw,
XtNwidth,(XtArgVal)width,
XtNallowHoriz,(XtArgVal)False,
XtNallowVert,(XtArgVal)True,
XtNshowGrip,(XtArgVal)False,
XtNskipAdjust,(XtArgVal)True,NULL);
}
/* setup the user menu */
{ char rcfile[256];
FILE *f;
/* try to find the HOME_DIR_FILE */
sprintf(rcfile,"~/%s",HOME_DIR_FILE);
expand_tilder(rcfile);
if((f = fopen(rcfile,"r")) == (FILE *) NULL) {
/* try the DEFAULT_RC_FILE */
strcpy(rcfile,DEFAULT_RC_FILE);
if((f = fopen(rcfile,"r")) == (FILE *) NULL) {
fprintf(stderr,"xbmbrowser: Can not find a menu definition file\n");
fprintf(stderr," looking for: ~/%s \n or %s\n",
HOME_DIR_FILE, DEFAULT_RC_FILE);
DoQuit();
}
}
fclose(f);
Create_user_menu(phw ,"bitmapMenu",rcfile);
}
/* setup the bow to hold all the bitmaps */
{ int width,fore,back,depth;
XtVaGetValues(toplevel,XtNwidth,&width,NULL);
/* create the box widget to put all the bitmaps in */
bw = XtVaCreateManagedWidget("bitmaps",boxWidgetClass,phw,
XtNwidth,width,
XtNorientation,(XtArgVal)XtorientVertical,
XtNfromVert,(XtArgVal)lw,
NULL);
/* find and set the stipple background pattern */
XtVaGetValues(bw, XtNborderColor, &fore,
XtNbackground, &back,
XtNdepth, &depth, NULL);
stipple = XmuCreateStippledPixmap(XtScreen(phw), fore, back, depth);
XtVaSetValues(bw, XtNbackgroundPixmap, (XtArgVal)stipple, NULL);
}
scan_bitmaps();
XtRealizeWidget(toplevel);
/* Set the window to call quit() action if `deleted' */
XtOverrideTranslations(toplevel,
XtParseTranslationTable("<Message>WM_PROTOCOLS:quit()") );
wm_delete_window = XInternAtom(XtDisplay(toplevel),"WM_DELETE_WINDOW",False);
(void) XSetWMProtocols(XtDisplay(toplevel), XtWindow(toplevel),
&wm_delete_window, 1);
XtAppMainLoop(appcon);
exit(0);
}
useage()
{
fprintf(stderr,"\nxbmbrowser: Usage: \nxbmbrowser [toolkit options] [<Dir>]\n");
fprintf(stderr,"\nWhere <Dir> is a directory name. \n");
exit(1);
}